﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BSCMFF.Core.DataAccessLayer;
using BSCMFF.Core.Exceptions.Database;

namespace BSCMFF.Core.BusinessLayer
{
    public class EvaluationManager
    {
        public void DeleteEvaluationEvaluatorEmployee(int eeeID)
        {
            BSCEntities context = new BSCEntities();

            List<Evaluation_User_Question_Value> values = (from v in context.Evaluation_User_Question_Value
                                                     where v.EEE_FK == eeeID
                                                     select v).ToList();

            foreach (Evaluation_User_Question_Value ev in values)
            {
                context.DeleteObject(ev);
            }


            Evaluation_Evaluator_Employee eee = (from e in context.Evaluation_Evaluator_Employee
                                                 where e.ID == eeeID
                                                 select e).SingleOrDefault();
            eee.Evaluated = false;

            //Evaluation_Period ep = (from e in context.Evaluation_Period
            //                        where e.ID == eee.Evaluation_FK
            //                        select e).SingleOrDefault();
            List<Evaluation_PKPIs> epkpis = (from ep in context.Evaluation_PKPIs
                                            where ep.EEE_FK == eeeID
                                            select ep).ToList();

            foreach (Evaluation_PKPIs p in epkpis)
            {
                p.Score = null;
                p.VerbalEvaluation = null;
                p.Note = null;
            }

            try
            {
                context.SaveChanges();
            }
            catch
            {
                throw new InconsistentDatabaseException("Couldn't delete evaluation");
            }
        }
    }
}
